 $(function() {
    	 var currentPageObj = $("#currentPage");
   		 var totalPageObj = $("#totalPage");
   		 var pagingForm = $("#pagingForm");
   		 var firstPageObj = $(".firstPage");
   		 var prePageObj = $(".prePage");
   		 var nextPageObj = $(".nextPage");
   		 var thisPageObj = $(".thisPage");
   		 var lastPageObj = $(".lastPage");
   		 var confirmSpecifyObj = $(".confirmSpecify");
   		 var specifyPage = $(".specifyPage");
   		 
   		 confirmSpecifyObj.click(function() {
   		 	for(var i=0; i<specifyPage.length; i++) {
   		 	    var nowPage = $(specifyPage[i]).val();
   		 	    var reg = new RegExp("^\\d*$");
   		 	    if(!reg.test(nowPage)) {
   		 	        alert("页码只能为数字！");
   		 	    	return false;
   		 	    }
				if($.trim(nowPage) != "") {
				    if(nowPage == currentPageObj.val()) {
				    	return false;
				    }
					currentPageObj.val(nowPage);
					createUrl();
					pagingForm.submit();
				}   		 	
   		 	}
   		 });
   		 
   		 firstPageObj.click(function() {
   		 	currentPageObj.val("1");
   		 	createUrl();
  			pagingForm.submit();
   		 });
   		 
   		 prePageObj.click(function() {
   		 	var currentPage = parseInt(currentPageObj.val());
	  		if(currentPage > 1) {
	  			currentPageObj.val(currentPage - 1);
	  		} else {
	  		 	currentPageObj.val(1);
	  		 	return false;
	  		}
	  		createUrl();
	  		pagingForm.submit();
   		 });
   		 
   		 nextPageObj.click(function() {
   		 	var currentPage = parseInt(currentPageObj.val());
	  		var totalPage = parseInt(totalPageObj.val());
	  		if(currentPage < totalPage) {
	  			currentPageObj.val(currentPage + 1);
	  		} else {
	  			currentPageObj.val(totalPage);
	  			return false;
	  		}
	  		createUrl();
	  		pagingForm.submit();
   		 });
   		 
   		 thisPageObj.click(function() {
   		 	currentPageObj.val($(this).html());
   		    createUrl();
  			pagingForm.submit();
   		 });
   		 
   		 lastPageObj.click(function() {
   		 	var totalPage = totalPageObj.val();
   		 	currentPageObj.val(totalPage);
   		    createUrl();
	  		pagingForm.submit();
   		 });
   		 
   		 $("#searchBtn").click(function() {
   		 	currentPageObj.val(1);
   		 	return true;
   		 });
    });
 
 function createUrl() {
	 var currentUrl = document.location.href;
	 if(currentUrl.indexOf("admin") == -1) {
		 var currentPageObj = $("#currentPage");
	     var totalPageObj = $("#totalPage");
		 var pagingForm = $("#pagingForm");
		 var url = pagingForm.attr("action");
		 url = url + "-" + currentPageObj.val() + "-" + totalPageObj.val()+".html";
		 pagingForm.attr("action", url);
	 }
 }
